package com.workstudy.wstudy.controller;

import java.util.List;

import com.workstudy.wstudy.domain.WstPostExamine;
import com.workstudy.wstudy.service.IWstPostExamineService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.workstudy.common.annotation.Log;
import com.workstudy.common.enums.BusinessType;
import com.workstudy.wstudy.domain.WstRecord;
import com.workstudy.wstudy.service.IWstRecordService;
import com.workstudy.common.core.controller.BaseController;
import com.workstudy.common.core.domain.AjaxResult;
import com.workstudy.common.utils.poi.ExcelUtil;
import com.workstudy.common.core.page.TableDataInfo;

/**
 * 审核记录Controller
 * 
 * @author sun
 * @date 2021-04-04
 */
@Controller
@RequestMapping("/wstudy/record")
public class WstRecordController extends BaseController
{
    private String prefix = "wstudy/record";

    @Autowired
    private IWstRecordService wstRecordService;
    @Autowired
    private IWstPostExamineService postExamineService;

    @RequiresPermissions("wstudy:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    @GetMapping("/examine/{postId}")
    public String examine(@PathVariable("postId")Long postId,ModelMap modelMap)
    {
        WstPostExamine paramsPostExamine = new WstPostExamine();
        paramsPostExamine.setPostId(postId);
        WstPostExamine postExamine = postExamineService.selectWstPostExamineById(postId);
        modelMap.put("postExamine",postExamine);
        return prefix + "/record_examine";
    }

    /**
     * 查询审核记录列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WstRecord wstRecord)
    {
        startPage();
        List<WstRecord> list = wstRecordService.selectWstRecordList(wstRecord);
        return getDataTable(list);
    }

    /**
     * 导出审核记录列表
     */
    @RequiresPermissions("wstudy:record:export")
    @Log(title = "审核记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WstRecord wstRecord)
    {
        List<WstRecord> list = wstRecordService.selectWstRecordList(wstRecord);
        ExcelUtil<WstRecord> util = new ExcelUtil<WstRecord>(WstRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增审核记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存审核记录
     */
    @RequiresPermissions("wstudy:record:add")
    @Log(title = "审核记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WstRecord wstRecord)
    {
        return toAjax(wstRecordService.insertWstRecord(wstRecord));
    }

    /**
     * 修改审核记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WstRecord wstRecord = wstRecordService.selectWstRecordById(id);
        mmap.put("wstRecord", wstRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存审核记录
     */
    @RequiresPermissions("wstudy:record:edit")
    @Log(title = "审核记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WstRecord wstRecord)
    {
        return toAjax(wstRecordService.updateWstRecord(wstRecord));
    }

    /**
     * 删除审核记录
     */
    @RequiresPermissions("wstudy:record:remove")
    @Log(title = "审核记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wstRecordService.deleteWstRecordByIds(ids));
    }
}
